package com.lz.football.module.activity.LevelWard
{
	import com.common.utils.Reflection;
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.events.ActivityEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.model.AppData;
	import com.lz.football.module.activity.IActivity;
	
	import common.BaseView.BaseView;
	
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	
	import lz.controls.managers.TipsManager;
	
	public class LevelActivityView extends BaseView implements IActivity
	{
		/**
		 *领取的物品ID 
		 */
		private var _awardId:int;
		
		private var _list:Array = ["",
									"紫色球员包 \n紫色洗练卡",
									"橙色洗练卡 \n进攻药剂",
									"橙色洗练卡 \n进攻药剂",
									"橙色球员包 \n进攻药剂",
									null];
		
		public function LevelActivityView()
		{
			super();
		}
		
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.res.activity.levelActivity");
			if(symbolSkin == null)return;
			this.addChild(symbolSkin);
			_windowBg = symbolSkin.levelBg;
			_viewHeight = symbolSkin.height;
			_viewWidth = symbolSkin.width;
			isCloseBtn = true;
			isDrag = true;
			onResizeHandler();
			addEvtListener();
			moveClose(_viewWidth - 35,25);
			
			symbolSkin.clubLv.text = AppData.getInstance().clubDatamanager.clubInfo.level + "";
			
		}
		override public function addEvtListener():void
		{
			symbolSkin.btn_1.addEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.award_1.addEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			symbolSkin.award_2.addEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			symbolSkin.award_1.addEventListener(MouseEvent.ROLL_OVER,onOver1Handler);
			symbolSkin.award_2.addEventListener(MouseEvent.ROLL_OVER,onOver2Handler);
		}
		
		private function onOver2Handler(event:MouseEvent):void
		{
			// TODO Auto Generated method stub
			TipsManager.show(TipsConst.BASETIPS,{tip:_list[_awardId+ 1]});
		}
		
		private function onOver1Handler(event:MouseEvent):void
		{
			// TODO Auto Generated method stub
			TipsManager.show(TipsConst.BASETIPS,{tip:_list[_awardId]});
		}
		
		private function onOutHandler(event:MouseEvent):void
		{
			// TODO Auto Generated method stub
			TipsManager.hide();
		}
		/**
		 * 
		 * @param event
		 * 
		 */
		private function onClickHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_LEVEL_AWARD,{id:_awardId}));
		}
		override public function removeEvtListener():void
		{
			symbolSkin.btn_1.removeEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.award_1.removeEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			symbolSkin.award_2.removeEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			symbolSkin.award_1.removeEventListener(MouseEvent.ROLL_OVER,onOver1Handler);
			symbolSkin.award_2.removeEventListener(MouseEvent.ROLL_OVER,onOver2Handler);
			super.removeEvtListener();
		}
		override public function destroyView():void
		{
			removeEvtListener();
			super.destroyView();
			
		}
		override public function onCloseHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new ActivityEvent(ModuleEvent.REMOVE_MODULE));
		}
		/**
		 *活跃度信息 
		 * @param $obj
		 * 1.	未领取
		 * 2.	已领取
		 */
		public function baseinformation($obj:Object):void
		{
			if($obj.status1 <=1)
			{
				_awardId = 1;
				setStatue(20);
				return;
			}
			
			if($obj.status2 <=1)
			{
				_awardId = 2;
				setStatue(30);
				return;
			}
			
			if($obj.status3 <=1)
			{
				_awardId = 3;
				setStatue(40);
				return;
			}
			
			if($obj.status4 <=1)
			{
				_awardId = 4;
				
				setStatue(50);
				return;
			}
			setStatue(60);
		}
		/**
		 *设置状态  
		 * 
		 */
		private function setStatue($lv:int):void
		{
			var clubLv:int = AppData.getInstance().clubDatamanager.clubInfo.level;
			if($lv <= clubLv)
			{
				symbolSkin.award_1.gotoAndStop(1);
				symbolSkin.leven_1.htmlText =  "<font color = '#FFFF00'>"+($lv)+ "级"+"<\font>";
				this.mouseEnabled = true;
				symbolSkin.btn_1.mouseEnabled = true;
				symbolSkin.btn_1.filters = null;
			}else
			{
				symbolSkin.award_1.gotoAndStop(2);
				symbolSkin.leven_1.htmlText =  "<font color = '#CCCCCC'>"+($lv)+ "级"+"<\font>";
				symbolSkin.btn_1.mouseEnabled = false;
				symbolSkin.btn_1.filters = [new ColorMatrixFilter([0.3086, 0.6094, 0.082, 0, 0,
					0.3086, 0.6094, 0.082, 0, 0,
					0.3086, 0.6094, 0.082, 0, 0,
					0,0,0,1,0,])];
			}
			if($lv + 10 <= clubLv)
			{
				
				symbolSkin.award_2.gotoAndStop(1);
				symbolSkin.con_2.htmlText = "<font color = '#FFFF00'>达到<\font>";
				symbolSkin.leven_2.htmlText = "<font color = '#FFFF00'>"+($lv + 10)+ "级"+"<\font>";
			}else
			{
				symbolSkin.con_2.htmlText = "<font color = '#FF0000'>未达到<\font>";
				symbolSkin.leven_2.htmlText = "<font color = '#CCCCCC'>"+($lv + 10)+ "级"+"<\font>";
				symbolSkin.award_2.gotoAndStop(2);
			}
			var temp:int = clubLv - $lv;
			if(temp <= 0)
			{
				symbolSkin.pro.gotoAndStop(1);
			}else if( temp >= 10)
			{
				symbolSkin.pro.gotoAndStop(10);
			}else
			{
				symbolSkin.pro.gotoAndStop(temp);
			}
			
			symbolSkin.leven_1.text =  $lv + "级";
//			symbolSkin.leven_2.text = ($lv + 10)+ "级";
			if($lv > 50)
			{
				
				symbolSkin.btn_1.visible = false;
				
				symbolSkin.award_1.gotoAndStop(2);
				symbolSkin.award_1.removeEventListener(MouseEvent.ROLL_OVER,onOver1Handler)
			}
			
			if($lv + 10 > 50)
			{
				symbolSkin.leven_2.text = "";
				symbolSkin.con_2.text = "";
				symbolSkin.award_2.gotoAndStop(2);
				symbolSkin.award_2.removeEventListener(MouseEvent.ROLL_OVER,onOver2Handler);
			}
			
		}
		/**
		 *领取奖励返回 
		 * 
		 */
		public function award($obj:Object):void
		{
			addEvtListener();
			if(!$obj.status)return;
			if($obj.id > 4)
			{
				symbolSkin.leven_2.text = "";
				symbolSkin.con_2.text = "";
				symbolSkin.leven_1.text = "";
				symbolSkin.btn_1.visible = false;
				removeEvtListener();
			}else
			{
				_awardId = $obj.id + 1;
				setStatue(($obj.id + 2) * 10);
			}
			
		}
	}
}